package com.example.demo.controller;

import com.example.demo.entity.ResponseInfo;
import com.example.demo.entity.UICaseStep;
import com.example.demo.entity.request.uiTestCaseStepReq.UITestCaseStepAddReq;
import com.example.demo.service.UICaseStepService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@Validated
@RequestMapping("/UITestCaseStep")
@Api(value = "/UITestCaseStep", tags = "ui测试用例步骤接口")
public class UICaseStepController {
    @Resource
    UICaseStepService uiCaseStepService;

    @PostMapping("/add")
    @ApiOperation(value = "ui测试用例步骤新增接口")
    public ResponseInfo<String> add(@RequestBody List<UITestCaseStepAddReq> uiTestCaseStepAddReqs) {
        uiCaseStepService.insert(uiTestCaseStepAddReqs);
        return ResponseInfo.successInfo("");
    }

    @PostMapping("/update")
    @ApiOperation(value = "ui测试用例步骤更新接口")
    public ResponseInfo<String> update(@RequestBody UICaseStep uiCaseStep) {
        uiCaseStepService.updateUICaseStep(uiCaseStep);
        return ResponseInfo.successInfo("");
    }

    @GetMapping("/ListByTestId")
    @ApiOperation(value = "根据测试用例Id查询测试步骤接口")
    @ApiImplicitParam(name = "testCaseId", value = "测试用例id", required = true, dataType = "Long")
    public ResponseInfo<List<UICaseStep>> ListByTestId(@RequestParam Long testCaseId) {
        return ResponseInfo.successInfo(uiCaseStepService.findByTestCaseId(testCaseId));
    }

    @DeleteMapping("/delete/{id}")
    @ApiOperation(value = "ui测试用例步骤删除接口")
    public ResponseInfo<String> delete(@PathVariable(value = "id") Long id) {
        uiCaseStepService.deleteStepById(id);
        return ResponseInfo.successInfo("");
    }
}
